import { computed, onBeforeUnmount, ref } from 'vue';

export function useFile(taskId) {
  const uploadable = ref(true);
  const controller = ref(new AbortController());
  controller.value.signal.addEventListener('abort', event => { uploadable.value = false });
  onBeforeUnmount(() => controller.value.abort());

  /** a-upload.fileList */
  const fileList = ref([]);

  /** 已上传文件数 */
  const countUploaded = ref(0);
  const uploading = computed(() => countUploaded.value < fileList.value.length);
  const uploadFailedList = computed(() => R.filter(R.propEq('error', 'status'), fileList.value));

  function handleChange({ file, fileList }) {
  }
  
  return {
    uploadable,
    controller,
    fileList,
    countUploaded,
    uploading,
    uploadFailedList,
    handleChange,
  };
}
